package com.zs.blog.constant.enums;

import jakarta.annotation.Nullable;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @Title: ResponseResultEnum
 * @Author zs
 * @Package com.zs.blog.constant.enums
 * @Date 2024/9/28 21:57
 * @description: 响应枚举类
 */
@Getter
public enum ResponseResultEnum {

    SUCCESS(20000, "操作成功"),
    FAILURE(50000, "操作失败"),
    CATEGORY_EXIT_ARTICLE(70000, "分类下有文章"),
    TAG_EXIT_ARTICLE(70001, "标签下有文章"),
    UPDATE_USER_TYPE_SUCCESS(70002, "更新用户状态成功"),
    UPDATE_USER_TYPE_FAILURE(70003, "更新用户状态失败");

    final Integer code;
    final String message;

    ResponseResultEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 根据枚举编码获取枚举说明
     *
     * @param code 枚举
     * @return 枚举说明
     */
    public static String getEnumValue(Integer code) {
        for (ResponseResultEnum rre : values()) {
            if (rre.getCode().equals(code)) {
                return rre.getMessage();
            }
        }
        return null;
    }
}
